@extends('layouts.back_stage')
@section('content')
    <style>
        @media print {
            /*.TreeTable {display: block !important;}*/
            .p1Info,.p2Info{display: block !important;}
            .h3Info{display: block !important;}
        }
        @media screen {
            /*.TreeTable {display: none !important;}*/
            .p1Info,.p2Info{display: none !important;}
            .h3Info{display: none !important;}
        }
        .TreeTable,.FourTable{display: none !important;}
        .shopBg{background:#fff;overflow: hidden;margin:20px 0 10px 0;}
        .input-item{width:180px;padding-right: 0;margin-right:10px;}
        .tableBg{padding:30px;background:#fff;margin-top:10px;}
        .pagination-box{text-align: center;box-sizing:border-box;margin-top:20px;}
        .el-range-editor--small.el-input__inner{width:300px;}
        .el-date-editor .el-range-separator{padding:0 15px}
        .mini.el-table--mini th{padding:0;}
        .demo-table-expand {font-size: 0;width: 100%;}
        .demo-table-expand label {width: 90px;color: #99a9bf;}
        .demo-table-expand .formItem1 {margin-right: 0;margin-bottom: 0;width: 100%;}
        .demo-table-expand .formItem2 {margin-right: 0;margin-bottom: 0;width: 96%;margin-left: 4%;}
        .el-checkbox+.el-checkbox{margin-left:0;}
        .el-table__expanded-cell[class*=cell]{padding: 10px 50px;}
        .el-form-item__content{line-height: 25px;}
        .el-checkbox__label{font-size:12px;}

        .touching{float:right;margin-right:30px;}
        .el-button+.el-button.picking{float:right;margin-right:15px;margin-left:0;}

        .el-table__expanded-cell[class*=cell]{padding:0 !important;}
        .el-table .divBg{padding:10px 50px;}
        .demo-table-expand {font-size: 0;}
        .demo-table-expand label {width: 90px;color: #606266;line-height:30px;font-size: 12px;}
        .demo-table-expand .el-form-item__content{line-height:30px;font-size: 12px;}
        .demo-table-expand .el-form-item {margin-right: 0;margin-bottom: 0;width: 25%;}

        .el-table tr:hover>td{background:initial !important;}
        .el-table tr.current-row>td{background:initial !important;}
        .el-table--striped .el-table__body tr.el-table__row--striped.current-row td, .el-table__body tr.current-row>td, .el-table__body tr.hover-row.current-row>td, .el-table__body tr.hover-row.el-table__row--striped.current-row>td, .el-table__body tr.hover-row.el-table__row--striped>td, .el-table__body tr.hover-row>td{background:initial !important;}

        .el-table .bgGreen {background:#c1e2b3;}
        .el-table .bgYellow{background:#ffff99;}
        .el-select .el-input .el-select__caret.el-input__icon{line-height:22px;}
        .borderBg .el-table::before{height:0 !important;}
        /*汇总*/
        .huiRow{float:left;width:33.333%;height:70px;line-height:70px;text-align:center;border-right:1px solid #6C6A6C;}
        .huiRow label,.huiRow .laDiv{height:35px;line-height:35px;float:left;width: 100%;font-size:16px;}

        .spTip{width:20px;height:20px;display:inline-block;margin:0 5px 0 20px;}
        ::-webkit-scrollbar {height: 8px;}
        .el-table__footer-wrapper tbody td, .el-table__header-wrapper tbody td{color:red;}
        [v-cloak] {display: none;}
    </style>
    <div class="container">
        <div style="padding:20px 20px 20px 0;overflow:hidden;"><h3 style="float:left;">退货入库</h3></div>
        <!-- 主体-->
        <div class="page-body">
            <div class="row app" id="guanLi" v-loading="loading" v-cloak>
                <el-button type="primary" class="touching" size="small" @click="exportBtn">导出</el-button>
                <el-button type="primary" class="picking" size="small" @click="preview()">打印</el-button>
                <div class="col-md-12 row row-table-box">
                    <div class="shopBg">
                        <div class="row" style="margin-top:10px;padding:9px 30px;background:#fff;">
                            <label>单据号：</label>
                            <el-input v-model.trim="order_num" class="input-item" placeholder="请输入单据号" size="small" prefix-icon="el-icon-search" clearable></el-input>
                            <label>款号：</label>
                            <el-input v-model.trim="girard" class="input-item" placeholder="请输入款号" size="small" prefix-icon="el-icon-search" clearable></el-input>
                            <label>制单人：</label>
                            <el-input v-model.trim="founder" class="input-item" placeholder="请输入制单人" size="small" prefix-icon="el-icon-search" clearable></el-input>
                            <div style="display:inline-block;padding:10px 0;">
                                <label>制单时间：</label>
                                <el-date-picker v-model="getDatas" @change="getTime" type="daterange" value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" size="small"></el-date-picker>
                                <el-button type="primary" size="small" @click="grabble('reset')">搜索</el-button>
                                <el-button type="primary" @click="resetFrom()" size="small">重置</el-button>
                            </div>
                        </div>
                    </div>
                    <div class="shopBg" style="margin-top:10px;padding:15px 30px;height:100px;background:#fff;">
                        <div class="huiRow">
                            <label>退货数量/件</label>
                            <div class="laDiv">@{{ nums_total }}</div>
                        </div>
                        <div class="huiRow">
                            <label>总金额/元</label>
                            <div class="laDiv">@{{ prices_total }}</div>
                        </div>
                        <div class="huiRow" style="border-right:none;">
                            <label>仓库扫描数量/件</label>
                            <div class="laDiv">@{{ scan_total }}</div>
                        </div>
                    </div>
                    <div class="tableBg borderBg">
                        <p style="height:20px;line-height:20px;display: inline-flex;float: right;">
                            <span class="spTip" style="background:#ffff99;"></span>退货中
                            <span class="spTip" style="background:#c1e2b3;"></span>退货完成
                        </p>
                        <el-table :data="tableInfo" max-height="510" size="mini" style="width: 100%;" @row-click="rowClick" @filter-change="filterChange" tooltip-effect="dark" @selection-change="handleSelectionChange" :row-class-name="tableRowClassName">
                            <el-table-column type="expand">
                                <template slot-scope="scope">
                                    <div v-if="scope.row.bgColor===''" class="divBg">
                                        <el-form label-position="left" inline class="demo-table-expand">
                                            <el-form-item label="制单日期:"><span>@{{ scope.row.created_at }}</span></el-form-item>
                                            <el-form-item label="制单人:"><span>@{{ scope.row.founder }}</span></el-form-item>
                                            <el-form-item label="审核时间:"><span>@{{ scope.row.check_time }}</span></el-form-item>
                                            <el-form-item label="审核人:"><span>@{{ scope.row.checker }}</span></el-form-item>
                                            <el-form-item label="确认时间:"><span>@{{ scope.row.ack_time }}</span></el-form-item>
                                            <el-form-item label="确认人:"><span>@{{ scope.row.acker }}</span></el-form-item>
                                            <el-form-item label="修改时间:"><span>@{{ scope.row.last_modified_time }}</span></el-form-item>
                                            <el-form-item label="修改人:"><span>@{{ scope.row.last_modified }}</span></el-form-item>
                                            <el-form-item style="width:100%;" label="备注:"><span>@{{ scope.row.remark }}</span></el-form-item>
                                        </el-form>
                                    </div>
                                    <div v-if="scope.row.bgColor==='bgYellow'" class="bgYellow divBg">
                                        <el-form label-position="left" inline class="demo-table-expand">
                                            <el-form-item label="制单日期:"><span>@{{ scope.row.created_at }}</span></el-form-item>
                                            <el-form-item label="制单人:"><span>@{{ scope.row.founder }}</span></el-form-item>
                                            <el-form-item label="审核时间:"><span>@{{ scope.row.check_time }}</span></el-form-item>
                                            <el-form-item label="审核人:"><span>@{{ scope.row.checker }}</span></el-form-item>
                                            <el-form-item label="确认时间:"><span>@{{ scope.row.ack_time }}</span></el-form-item>
                                            <el-form-item label="确认人:"><span>@{{ scope.row.acker }}</span></el-form-item>
                                            <el-form-item label="修改时间:"><span>@{{ scope.row.last_modified_time }}</span></el-form-item>
                                            <el-form-item label="修改人:"><span>@{{ scope.row.last_modified }}</span></el-form-item>
                                            <el-form-item style="width:100%;" label="备注:"><span>@{{ scope.row.remark }}</span></el-form-item>
                                        </el-form>
                                    </div>
                                    <div v-if="scope.row.bgColor==='bgGreen'" class="bgGreen divBg">
                                        <el-form label-position="left" inline class="demo-table-expand">
                                            <el-form-item label="制单日期:"><span>@{{ scope.row.created_at }}</span></el-form-item>
                                            <el-form-item label="制单人:"><span>@{{ scope.row.founder }}</span></el-form-item>
                                            <el-form-item label="审核时间:"><span>@{{ scope.row.check_time }}</span></el-form-item>
                                            <el-form-item label="审核人:"><span>@{{ scope.row.checker }}</span></el-form-item>
                                            <el-form-item label="确认时间:"><span>@{{ scope.row.ack_time }}</span></el-form-item>
                                            <el-form-item label="确认人:"><span>@{{ scope.row.acker }}</span></el-form-item>
                                            <el-form-item label="修改时间:"><span>@{{ scope.row.last_modified_time }}</span></el-form-item>
                                            <el-form-item label="修改人:"><span>@{{ scope.row.last_modified }}</span></el-form-item>
                                            <el-form-item style="width:100%;" label="备注:"><span>@{{ scope.row.remark }}</span></el-form-item>
                                        </el-form>
                                    </div>
                                </template>
                            </el-table-column>
                            <el-table-column type="selection" width="55"></el-table-column>
                            <el-table-column prop="loop" label="序号" width="50" :resizable='false'></el-table-column>
                            <el-table-column prop="order_num" label="单据号" min-width="120" :resizable='false'></el-table-column>
                            <el-table-column prop="order_type" label="制单类型" min-width="90" :resizable='false' column-key="order_type" :filters="[{ text: '手工制单', value: '2' }, { text: '扫码制单', value: '3' }]">
                                <template slot-scope="scope">
                                    <span v-if="scope.row.order_type===2">手工制单</span>
                                    <span v-if="scope.row.order_type===3">扫码制单</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="customer" label="客户" min-width="100" :resizable='false'></el-table-column>
                            <el-table-column prop="factory_type" label="退货仓库" min-width="100" :resizable='false' column-key="factory_type" :filters="send_type"></el-table-column>
                            <el-table-column prop="nums" label="退货数量/件" min-width="100" :resizable='false'></el-table-column>
                            <el-table-column prop="price" label="总金额/元" min-width="100" align="right" :resizable='false'></el-table-column>
                            <el-table-column prop="check_nums" label="扫描数量/件" min-width="120" :resizable='false'></el-table-column>
                            <el-table-column prop="is_distribution" label="退货状态" min-width="90" :resizable='false' column-key="is_distribution" :filters="[{ text: '未退货', value: '0' }, { text: '退货中', value: '1' }, { text: '退货完成', value: '2' }]">
                                <template slot-scope="scope">
                                    <span v-if="scope.row.is_distribution===0">未退货</span>
                                    <span v-if="scope.row.is_distribution===1">退货中</span>
                                    <span v-if="scope.row.is_distribution===2">退货完成</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="sale_season" label="销售季节" width="120" :resizable='false' column-key="sale_season" :filters="season_type"></el-table-column>
                            <el-table-column prop="company" label="所属公司" min-width="165" :resizable='false'></el-table-column>
                            <el-table-column label="操作" fixed="right" min-width="110">
                                <template slot-scope="scope">
                                    <el-button v-if="scope.row.is_distribution===0" type="text" size="small" @click="senOr(scope)">退货</el-button>
                                    <el-button v-if="scope.row.is_distribution===1" type="text" size="small" @click="continueOr(scope)">继续退货</el-button>
                                    <el-button  type="text" size="small" @click="lookOr(scope)">查看</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <div class="pagination-box"><el-pagination @size-change="handleSizeChange" :page-sizes="[10,50,100,200]" :page-size="10" @current-change="changePageSkip" :current-page.sync="currentPage" :total="total" layout="sizes,prev, pager, next" background></el-pagination></div>
                    </div>
                    <div class="tableBg">
                        <el-tabs v-model="activeName2" type="border-card">
                            <el-tab-pane label="手工退货明细" name="first" :disabled="first">
                                <el-table :data="tbInfo" class="mini" size="mini" border style="margin-top:20px;" :summary-method="getSummaries" show-summary>
                                    <el-table-column prop="year" width="55" label="年份" :resizable='false'></el-table-column>
                                    <el-table-column prop="season" width="55" label="季节" :resizable='false'></el-table-column>
                                    <el-table-column prop="girard" label="款号" min-width="100" :resizable='false'></el-table-column>
                                    <el-table-column prop="color" label="颜色" min-width="70" :resizable='false'></el-table-column>
                                    <el-table-column prop="price" label="吊牌价/元" align="right" width="130" :resizable='false'></el-table-column>
                                    <el-table-column prop="disPrice" label="折扣价/元" align="right" width="130" :resizable='false'></el-table-column>
                                    <el-table-column prop="discount" label="折扣" width="50" :resizable='false'></el-table-column>

                                    <el-table-column v-for="item in sizeGr"  :label="item.key76" width="70" :resizable='false'>
                                        <el-table-column :label="item.key75" width="70" :resizable='false'>
                                            <el-table-column :label="item.key79" width="70" :resizable='false'>
                                                <el-table-column :label="item.key154" width="70" :resizable='false'>
                                                    <el-table-column :label="item.key146" width="70" :resizable='false'>
                                                        <el-table-column :label="item.key161" width="70" :resizable='false'>
                                                            <el-table-column :label="item.key77" width="70" :resizable='false'>
                                                                <el-table-column :prop="item.key_0" :label="item.key140" width="70" :resizable='false'></el-table-column>
                                                            </el-table-column>
                                                        </el-table-column>
                                                    </el-table-column>
                                                </el-table-column>
                                            </el-table-column>
                                        </el-table-column>
                                    </el-table-column>

                                    <el-table-column prop="count" label="合计/件" width="70" :resizable='false'></el-table-column>
                                    <el-table-column prop="disCount" label="折扣金额/元" align="right" width="120" :resizable='false'></el-table-column>
                                    <el-table-column prop="cardCount" label="吊牌金额/元" align="right" width="120" :resizable='false'></el-table-column>
                                </el-table>
                            </el-tab-pane>
                            <el-tab-pane label="扫码退货明细" name="second" :disabled="second">
                                <el-table :data="tuiCodes" max-height="510" style="width: 100%;" size="mini" border>
                                    <el-table-column type="index" label="序号" width="50" :resizable='false'></el-table-column>
                                    <el-table-column prop="brand" label="品牌" :resizable='false'></el-table-column>
                                    <el-table-column prop="year" label="年份" :resizable='false'></el-table-column>
                                    <el-table-column prop="season" label="季节" :resizable='false'></el-table-column>
                                    <el-table-column prop="cate_3" label="小类" :resizable='false'></el-table-column>
                                    <el-table-column prop="girard" label="款号" :resizable='false'></el-table-column>
                                    <el-table-column prop="color" label="颜色" :resizable='false'></el-table-column>
                                    <el-table-column prop="size" label="尺码" :resizable='false'></el-table-column>
                                    <el-table-column prop="price" label="吊牌价/元" align="right" width="100" :resizable='false'></el-table-column>
                                    <el-table-column prop="code" width="160" label="服装条码" :resizable='false'></el-table-column>
                                    <el-table-column prop="scan_admin" label="扫描人" :resizable='false'></el-table-column>
                                    <el-table-column prop="created_at" width="160" label="扫描时间" :resizable='false'></el-table-column>
                                </el-table>
                            </el-tab-pane>
                        </el-tabs>
                    </div>
                </div>
            </div>
            <!--startprint-->
            <style>
                .TreeTable > thead > tr > th, .TreeTable > tbody > tr > th, .TreeTable > tfoot > tr > th, .TreeTable > thead > tr > td, .TreeTable > tbody > tr > td, .TreeTable > tfoot > tr > td{padding:4px 8px;}
                .table-bordered > thead > tr > th, .table-bordered > tbody > tr > th, .table-bordered > tfoot > tr > th, .table-bordered > thead > tr > td, .table-bordered > tbody > tr > td, .table-bordered > tfoot > tr > td{border: 1px solid #000;}
                .TreeTable > thead > tr > th, .TreeTable > tbody > tr > th, .TreeTable > tfoot > tr > th, .TreeTable > thead > tr > td, .TreeTable > tbody > tr > td, .TreeTable > tfoot > tr > td{border: 1px solid #000;}
                .TreeInfo > thead > tr > th, .TreeInfo > tbody > tr > th, .TreeInfo > tfoot > tr > th, .TreeInfo > thead > tr > td, .TreeInfo > tbody > tr > td, .TreeInfo > tfoot > tr > td{padding:2px 8px;}
                .table>caption+thead>tr:first-child>td, .table>caption+thead>tr:first-child>th, .table>colgroup+thead>tr:first-child>td, .table>colgroup+thead>tr:first-child>th, .table>thead:first-child>tr:first-child>td, .table>thead:first-child>tr:first-child>th{border-top: 1px solid #000;}
                .TreeInfo{margin-top:10px;}
                .TreeTable > thead > tr > th, .TreeTable > tbody > tr > th, .TreeTable > tfoot > tr > th, .TreeTable > thead > tr > td, .TreeTable > tbody > tr > td, .TreeTable > tfoot > tr > td{padding: 0px 8px;}
                .FourTable > thead > tr > th, .FourTable > tbody > tr > th, .FourTable > tfoot > tr > th, .FourTable > thead > tr > td, .FourTable > tbody > tr > td, .FourTable > tfoot > tr > td{padding: 0px 8px;}
            </style>
            <h3 class="h3Info" style="width:100%;height:30px;text-align:center;font-size:20px;">批发退货单</h3>
            <p class="p1Info"></p>
            <p class="p2Info"></p>
            <table class="table table-bordered TreeTable" border="1" bordercolor="#000000" style="border-collapse:collapse;margin-bottom:0;font-size:12px;">
                <thead>

                </thead>
                <tbody>

                </tbody>
            </table>
            <table class="table table-bordered FourTable" border="1" bordercolor="#000000" style="border-collapse:collapse;margin-bottom:0;font-size:12px;">
                <thead>
                <tr class="text-center">
                    <th class="text-center">品牌</th>
                    <th class="text-center">年份</th>
                    <th class="text-center">季节</th>
                    <th class="text-center">小类</th>
                    <th class="text-center">款号</th>
                    <th class="text-center">颜色</th>
                    <th class="text-center">尺码</th>
                    <th class="text-center">吊牌价/元</th>
                    <th class="text-center">服装条码</th>
                    <th class="text-center">扫描人</th>
                    <th class="text-center">扫描时间</th>
                </tr>
                </thead>
                <tbody>

                </tbody>
            </table>
            <!--endprint-->
        </div>
        <!-- /主体-->
    </div>

    <script>
        new Vue({
            el: '#guanLi',
            data:{
                sizeGr:[],//尺码信息
                //汇总
                scan_total:'',//仓库扫描数量
                nums_total:'',//数量
                prices_total:'',//总金额
                girardNum:'',//款号种类合计

                tableInfo:[], //表单数据
                tbInfo:[],//详细表单数据
                total:1,  //table总条数
                currentPage:1, //table当前页数
                page:10,//每页多少条
                ids:'',//多选框id拼起来


                tuiCodes:[],

                order_num:'',//单据号
                girard:'',//款号
                founder:'',//制单人
                getDatas:'', //起止时间
                created_at:'', //起止时间存储变量
                order_type:'',//制单类型
                send_type:[],//退货仓库数据
                factory_type:'',//退货仓库

                is_distribution:'',//退货状态
                season_type:[],//销售季节数据
                sale_season:'',//销售季节

                //验证数据用
                peiArr:[],//退货状态数组
                loading:false,

                //卡片选择
                activeName2: 'first',
                first:false,
                second:false,
            },
            created(){
                this.loading=true;
            },
            mounted(){
                this.common();
                this.grabble();
                this.baseIn();
            },
            methods:{
                /*尺码数据*/
                common(){
                    var that=this;
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                        },
                        type: 'post',
                        url: '/distribution/sizeGroupHead',
                        data: {
                            type:1,
                        },
                        success: function (data) {
                            //console.log(data);
                            if(data.result.success){
                                that.sizeGr=data.content.vertical;
                                let fb=Number(data.content.horizontal.length)+1;
                                let len=0;
                                let ses='';
                                for(let even in data.content.horizontal[0]){
                                    len++;
                                }
                                let saz='<tr class="text-center">' +
                                    '<th rowspan='+fb+' style="vertical-align:middle;text-align:center;">年份</th>' +
                                    '<th rowspan='+fb+' style="vertical-align:middle;text-align:center;">季节</th>' +
                                    '<th rowspan='+fb+' style="vertical-align:middle;text-align:center;">款号</th>' +
                                    '<th rowspan='+fb+' style="vertical-align:middle;text-align:center;">颜色</th>' +
                                    '<th rowspan='+fb+' style="vertical-align:middle;text-align:center;">吊牌价/元</th>' +
                                    '<th rowspan='+fb+' style="vertical-align:middle;text-align:center;">折扣价/元</th>' +
                                    '<th rowspan='+fb+' style="vertical-align:middle;text-align:center;">折扣</th>' +
                                    '<th colspan='+len+' class="text-center">尺码信息</th>' +
                                    '<th class="text-center" rowspan='+fb+' style="vertical-align:middle;">合计/件</th>' +
                                    '<th class="text-center" rowspan='+fb+' style="vertical-align:middle;">折扣金额/元</th>' +
                                    '<th class="text-center" rowspan='+fb+' style="vertical-align:middle;">吊牌金额/元</th>' +
                                    '</tr>';
                                for(let bv of data.content.horizontal){
                                    ses=ses+'<tr>' +
                                        '<th class="text-center">'+bv.k0+'</th>' +
                                        '<th class="text-center">'+bv.k1+'</th>' +
                                        '<th class="text-center">'+bv.k2+'</th>' +
                                        '<th class="text-center">'+bv.k3+'</th>' +
                                        '<th class="text-center">'+bv.k4+'</th>' +
                                        '<th class="text-center">'+bv.k5+'</th>' +
                                        '<th class="text-center">'+bv.k6+'</th>' +
                                        '<th class="text-center">'+bv.k7+'</th>' +
                                        '<th class="text-center">'+bv.k8+'</th>' +
                                        '<th class="text-center">'+bv.k9+'</th>' +
                                        '<th class="text-center">'+bv.k10+'</th>' +
                                        '<th class="text-center">'+bv.k11+'</th>' +
                                        '<th class="text-center">'+bv.k12+'</th>' +
                                        '</tr>';
                                }

                                $(".TreeTable thead").append(saz);
                                $(".TreeTable thead").append(ses);
                            }else{
                                that.$notify.error({
                                    title: '提示',
                                    message: data.result.errorMsg,
                                });
                            }
                        }
                    });
                },
                /*搜索下拉框*/
                baseIn(){
                    var that=this;
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                        },
                        type: 'post',
                        url: '/distribution/extra-infos',
                        data: {
                            type:1,
                        },
                        success: function (data) {
                            //console.log(data);
                            if(data.result.success){
                                var st1=[];
                                for(var value of data.content.factory_type){
                                    st1.push({
                                        'text':value.type,
                                        'value':value.id,
                                    })
                                }
                                var st2=[];
                                for(var value of data.content.sale_season){
                                    st2.push({
                                        'text':value.season,
                                        'value':value.id,
                                    })
                                }
                                that.send_type=st1;
                                that.season_type=st2;
                            }else{
                                that.$notify.error({
                                    title: '提示',
                                    message: data.result.errorMsg,
                                });
                            }
                        }
                    });
                },
                //获取数据
                grabble(type){
                    var that = this;
                    let skip;
                    if(type == 'reset'){
                        skip = 0;
                    }else{
                        skip = that.currentPage-1;
                    }
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                        },
                        type: 'post',
                        url: '/distribution/warehouse-thd-list',
                        data: {
                            skip:skip,
                            page:that.page,
                            order_num:that.order_num,
                            girard:that.girard,
                            founder:that.founder,
                            created_at:that.created_at,
                            order_type:that.order_type,
                            factory_type:that.factory_type,

                            is_distribution:that.is_distribution,
                            sale_season:that.sale_season,
                        },
                        success: function (data) {
                            //console.log(data);
                            if(data.result.success){
                                that.nums_total=data.content.nums_total;
                                that.prices_total=parseFloat(data.content.prices_total).toFixed(2);
                                that.scan_total=data.content.scan_total;
                                var opt=[];
                                let i = 0;
                                for(var value of data.content.data){
                                    i++;
                                    opt.push({
                                        'id':value.id,
                                        'loop':i+(Number(that.page)*skip),
                                        'order_num':value.order_num,
                                        'order_type':value.order_type,
                                        'customer':value.customer,
                                        'factory_type':value.factory_type,
                                        'nums':value.num,
                                        'price': parseFloat( value.price ).toFixed(2),
                                        'check_nums':value.check_num,

                                        'is_distribution':value.is_distribution,
                                        'sale_season':value.sale_season,
                                        'company':value.company,
                                        'created_at':value.created_at,
                                        'founder':value.founder,
                                        'check_time':value.check_time,
                                        'checker':value.checker,
                                        'ack_time':value.ack_time,
                                        'acker':value.acker,
                                        'last_modified':value.last_modified,
                                        'last_modified_time':value.last_modified_time,
                                        'remark':value.remark,
                                        'bgColor':that.getBgType(value.is_distribution)
                                    })
                                }
                                that.tableInfo = opt;
                                that.currentPage = parseFloat( data.content.skip );
                                that.total = data.content.total;
                                that.loading=false
                            }else{
                                that.$notify({
                                    title: '提示',
                                    message: data.result.errorMsg,
                                    duration: 0
                                });
                            }
                        }
                    });
                },
                getTime(date){
                    if(date==null){
                        this.getDatas='';
                        this.created_at ='';
                    }else{
                        this.getDatas=date;
                        this.created_at =date[0]+' - '+date[1];
                    }
                },
                /*重置*/
                resetFrom(){
                    this.order_num='';
                    this.girard='';
                    this.founder='';
                    this.getDatas='';
                    this.created_at='';
                    this.order_type='';
                    this.factory_type='';
                    this.is_distribution='';
                    this.sale_season='';
                    this.grabble('reset')
                },
                changePageSkip(val){
                    //console.log(`当前页: ${val}`);
                    this.currentPage = val;
                    this.grabble();
                },
                handleSizeChange(val) {
                    this.page=val;
                    this.grabble('reset');
                    //console.log(`每页 ${val} 条`);
                },
                /*状态搜索*/
                filterChange(filters){
                    //console.log(filters)
                    if(filters.order_type!=undefined){
                        var fil0=filters.order_type;
                        var stas0='';
                        for(let dq=0;dq<fil0.length; dq++){
                            stas0=stas0+fil0[dq]+',';
                        }
                        this.order_type=stas0.substr(0, stas0.length - 1);
                        this.grabble('reset');
                    }

                    if(filters.is_distribution!=undefined){
                        var isArr=filters.is_distribution;
                        var stas5='';
                        for(let x=0;x<isArr.length; x++){
                            stas5=stas5+isArr[x]+',';
                        }
                        this.is_distribution=stas5.substr(0, stas5.length - 1);
                        this.grabble('reset');
                    }
                    if(filters.factory_type!=undefined){
                        var facArr=filters.factory_type;
                        var stas3='';
                        for(let x=0;x<facArr.length; x++){
                            stas3=stas3+facArr[x]+',';
                        }
                        this.factory_type=stas3.substr(0, stas3.length - 1);
                        this.grabble('reset');
                    }
                    if(filters.sale_season!=undefined){
                        var saleArr=filters.sale_season;
                        var stas4='';
                        for(let x=0;x<saleArr.length; x++){
                            stas4=stas4+saleArr[x]+',';
                        }
                        this.sale_season=stas4.substr(0, stas4.length - 1);
                        this.grabble('reset');
                    }
                },
                /*多选*/
                handleSelectionChange(val){
                    if(val.length>0){
                        var st='';
                        this.peiArr=[];
                        for(var value of val){
                            st=st+value.id+',';
                            this.peiArr.push(value.is_distribution);
                        }
                        this.ids=st.substr(0, st.length - 1);
                    }else{
                        this.ids='';
                        this.peiArr=[];
                    }
                    //console.log(this.ids);
                },
                /*退货*/
                senOr(scope){
                    var that=this;
                    const h = this.$createElement;
                    this.$msgbox({
                        title: '提示',
                        message: h('p', null, [
                            h('span', null, '是否开启退货?'),
                        ]),
                        showCancelButton: true,
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        beforeClose: (action, instance, done) => {
                            if (action === 'confirm') {
                                $.ajax({
                                    headers: {
                                        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                                    },
                                    type: 'post',
                                    url: '/distribution/return-order-start',
                                    data: {
                                        id:scope.row.id,
                                    },
                                    success: function (data) {
                                        //console.log(data);
                                        if(data.result.success){
                                            done();
                                            if(scope.row.order_type==2){
                                                window.location.href='/distribution/pfthd-warehouse-manual/'+scope.row.id+'?state=0';
                                            }else{
                                                window.location.href='/distribution/pfthd-warehouse-scan/'+scope.row.id+'?state=0';
                                            }
                                        }else{
                                            that.$notify.error({
                                                title: '提示',
                                                message: data.result.errorMsg,
                                            });
                                        }
                                    }
                                });
                            } else {
                                done();
                            }
                        }
                    }).then(action => {

                    });
                },
                /*继续退货*/
                continueOr(scope){
                    if(scope.row.order_type==2){
                        window.location.href='/distribution/pfthd-warehouse-manual/'+scope.row.id+'?state=0';
                    }else{
                        window.location.href='/distribution/pfthd-warehouse-scan/'+scope.row.id+'?state=0';
                    }
                },
                /*退货查看*/
                lookOr(scope){
                    if(scope.row.order_type==2){
                        window.location.href='/distribution/pfthd-warehouse-manual/'+scope.row.id+'?state=1';
                    }else{
                        window.location.href='/distribution/pfthd-warehouse-scan/'+scope.row.id+'?state=1';
                    }
                },
                /*背景颜色*/
                tableRowClassName({row, rowIndex}){
                    if(row.bgColor == ''){
                        return ""
                    }else if(row.bgColor == 'bgYellow'){
                        return "bgYellow"
                    }else if(row.bgColor == 'bgGreen'){
                        return "bgGreen"
                    }
                    return ''
                },
                getBgType(is_distribution){
                        if(is_distribution==0){
                            return ""
                        }else if(is_distribution==1){
                            return "bgYellow"
                        }else if(is_distribution==2){
                            return "bgGreen"
                        }
                        return ''
                },
                /*点击出详情*/
                rowClick(row, event, column) {
                    var that=this;
                    /*当事件源是a的时候，我们不展开*/
                    let nodeName = event.target.nodeName;
                    if(nodeName==='BUTTON'){
                        return;
                    }
                    if(nodeName==='SPAN'){
                        return;
                    }
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                        },
                        type: 'post',
                        url: '/distribution/pfth-scan-infos',
                        data: {
                            id:row.id
                        },
                        success: function (data) {
                            //console.log(data);
                            if(data.result.success){
                                if(data.content.data_1.length>0){
                                    var opt=[];
                                    let girardArr=[];
                                    for(var value of data.content.data_1){
                                        if(girardArr.indexOf(value.girard)==-1){
                                            girardArr.push(value.girard)
                                        };
                                        var cvs=0;
                                        for(var cv=0;cv<value.nums.length;cv++){
                                            if(value.nums[cv]==''){
                                                value.nums[cv]=0;
                                            }
                                            cvs+=Number(value.nums[cv]);
                                        }
                                        var oneNum=0;
                                        var twoNum=0;
                                        if(value.nums.length==9 && value.price.indexOf("/")!=-1){
                                            for(var cc=0;cc<value.nums.length;cc++){
                                                if(value.nums[cc]==''){
                                                    value.nums[cc]=0;
                                                }
                                                if(cc<7){
                                                    oneNum+=Number(value.nums[cc]);
                                                }else{
                                                    twoNum+=Number(value.nums[cc]);
                                                }
                                            }
                                        }
                                        opt.push({
                                            'id':value.id,
                                            'year':value.year,
                                            'season':value.season,
                                            'girard':value.girard,
                                            'num':value.nums,
                                            'color':value.color,
                                            'price':value.price,
                                            'disPrice':that.getMon( value.price , value.discount),
                                            'discount':value.discount,
                                            'size_group':value.size_group,
                                            'count':cvs,
                                            'disCount':that.getDon( value.price , value.discount , oneNum , twoNum , cvs),
                                            'cardCount':that.getCou(value.price , oneNum , twoNum , cvs),
                                        })
                                    }
                                    that.girardNum=girardArr.length;
                                    that.activeName2='first';
                                    that.first=false;
                                    that.second=true;
                                    that.tbInfo = opt;
                                }else {
                                    that.tbInfo = [];
                                }
                                if(data.content.data_2.length>0){
                                    that.activeName2='second';
                                    that.first=true;
                                    that.second=false;
                                    that.tuiCodes = data.content.data_2;
                                }else{
                                    that.tuiCodes=[];
                                }
                                if(data.content.data_1.length<=0 && data.content.data_2.length<=0){
                                    that.first=false;
                                    that.second=false;
                                }
                            }else{
                                that.$notify.error({
                                    title: '提示',
                                    message: data.result.errorMsg,
                                });
                            }
                        }
                    });
                },
                /*折扣价*/
                getMon(money,dis){
                    if(money.indexOf("/")!=-1 && dis.indexOf("/")!=-1){
                        let priArr=money.split("/");
                        let disArr=dis.split("/");
                        let disPriOne=(priArr[0]*disArr[0]).toFixed(2);
                        let disPriTwo=(priArr[1]*disArr[1]).toFixed(2);
                        return disPriOne+'/'+disPriTwo
                    }else if(money.indexOf("/")!=-1 && dis.indexOf("/")==-1){
                        let priArr=money.split("/");
                        let disPriOne=(priArr[0]*dis).toFixed(2);
                        let disPriTwo=(priArr[1]*dis).toFixed(2);
                        return disPriOne+'/'+disPriTwo
                    }else if(money.indexOf("/")==-1 && dis.indexOf("/")!=-1){
                        let disArr=dis.split("/");
                        let disPriOne=(money*disArr[0]).toFixed(2);
                        let disPriTwo=(money*disArr[1]).toFixed(2);
                        return disPriOne+'/'+disPriTwo
                    }else{
                        return (money*dis).toFixed(2);
                    }
                },
                /*总折扣金额*/
                getDon(money,dis,n1,n2,n3){
                    if(money.indexOf("/")!=-1 && dis.indexOf("/")!=-1){
                        let priArr=money.split("/");
                        let disArr=dis.split("/");
                        let disPriOne=(priArr[0]*disArr[0]*n1);
                        let disPriTwo=(priArr[1]*disArr[1]*n2);
                        return (Number(disPriOne) + Number(disPriTwo)).toFixed(2);
                    }else if(money.indexOf("/")!=-1 && dis.indexOf("/")==-1){
                        let priArr=money.split("/");
                        let disPriOne=(priArr[0]*dis*n1);
                        let disPriTwo=(priArr[1]*dis*n2);
                        return (Number(disPriOne) + Number(disPriTwo)).toFixed(2);
                    }else if(money.indexOf("/")==-1 && dis.indexOf("/")!=-1){
                        let disArr=dis.split("/");
                        let disPriOne=(money*disArr[0]*n1);
                        let disPriTwo=(money*disArr[1]*n2);
                        return (Number(disPriOne) + Number(disPriTwo)).toFixed(2);
                    }else{
                        return (money*dis*n3).toFixed(2);
                    }
                },
                /*总吊牌金额*/
                getCou(money,n1,n2,n3){
                    if(money.indexOf("/")!=-1){
                        let priArr=money.split("/");
                        let disPriOne=(priArr[0]*n1);
                        let disPriTwo=(priArr[1]*n2);
                        return (Number(disPriOne) + Number(disPriTwo)).toFixed(2);
                    }else{
                        return (money*n3).toFixed(2);
                    }
                },
                /*合计*/
                getSummaries(param) {
                    var that=this;
                    const { columns, data } = param;
                    const sums = [];
                    columns.forEach((column, index) => {
                        if (index === 0) {
                            sums[index] = '合计';
                            return;
                        }
                        const values = data.map(item => Number(item[column.property]));
                        switch (column.property) {
                            case 'girard':
                                sums[index] = that.girardNum;
                                break;
                            case 'count':
                                sums[index] = values.reduce((prev, curr) => {
                                    const value = Number(curr);
                                    if (!isNaN(value)) {
                                        return prev + curr;
                                    } else {
                                        return prev;
                                    }
                                }, 0);
                                break;
                            case 'disCount':
                                sums[index] = values.reduce((prev, curr) => {
                                    const value = Number(curr);
                                    if (!isNaN(value)) {
                                        return ( parseFloat(prev) + parseFloat(curr) ).toFixed(2);
                                    } else {
                                        return parseFloat(prev).toFixed(2);
                                    }
                                }, 0);
                                break;
                            case 'cardCount':
                                sums[index] = values.reduce((prev, curr) => {
                                    const value = Number(curr);
                                    if (!isNaN(value)) {
                                        return ( parseFloat(prev) + parseFloat(curr) ).toFixed(2);
                                    } else {
                                        return parseFloat(prev).toFixed(2);
                                    }
                                }, 0);
                                break;
                            default:
                                break;
                        }
                    });
                    return sums
                },
                /*打印*/
                preview(){
                    var that=this;
                    //console.log(this.ids)
                    let idsArr=this.ids.split(",");
                    if(this.ids==''){
                        this.$notify.error({
                            title: '提示',
                            message: "请选择一个单据打印",
                        });
                        return false;
                    }
                    if(idsArr.length>1){
                        this.$notify.error({
                            title: '提示',
                            message: "请选择一个单据打印",
                        });
                        return false;
                    }
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                        },
                        type: 'post',
                        url: '/distribution/return-order-print',
                        data: {
                            id:that.ids,
                        },
                        success: function (data) {
                            //console.log(data);
                            if(data.result.success){
                                $(".p1Info").empty();
                                $(".p2Info").empty();
                                $(".p1Info").append('<span style="width:25%;display:inline-block;">单据号：'+data.content.head.order_num+'</span>' +
                                    '<span style="width:25%;display:inline-block;">退货仓库：'+data.content.head.fact_type+'</span>' +
                                    '<span style="width:25%;display:inline-block;">客户：'+data.content.head.customer_name+'</span>' +
                                    '<span style="width:25%;display:inline-block;">销售季节：'+data.content.head.season+'</span>');
                                $(".p2Info").append('<span style="width:25%;display:inline-block;">打印时间：'+data.content.head.created_at+'</span>' +
                                    '<span style="width:25%;display:inline-block;">制单人：'+data.content.head.founder+'</span>' +
                                    '<span style="width:50%;display:inline-block;">备注：'+data.content.head.remark+'</span>');
                                if(data.content.data_1.length>0){
                                    var ste='';
                                    for(var value of data.content.data_1){
                                        var cvs=0;
                                        for(var cv=0;cv<value.nums.length;cv++){
                                            if(value.nums[cv]==''){
                                                value.nums[cv]=0;
                                            }
                                            if(value.nums[cv]=='undefined'){
                                                value.nums[cv]='';
                                            }
                                            cvs+=Number(value.nums[cv]);
                                            var oneNum=0;
                                            var twoNum=0;
                                            if(value.nums.length==9 && value.price.indexOf("/")!=-1){
                                                for(var cc=0;cc<value.nums.length;cc++){
                                                    if(value.nums[cc]==''){
                                                        value.nums[cc]=0;
                                                    }
                                                    if(cc<7){
                                                        oneNum+=Number(value.nums[cc]);
                                                    }else{
                                                        twoNum+=Number(value.nums[cc]);
                                                    }

                                                }
                                            }
                                        }
                                        var sum=[];
                                        for(var cz=0;cz<12;cz++){
                                            if(value.nums[cz]==undefined){
                                                sum.push('');
                                                value.nums[cz]='';
                                            }else{
                                                sum.push(value.nums[cz]);
                                            }
                                        }
                                        ste=ste+'<tr>' +
                                            '<td class="text-center">'+value.year+'</td>' +
                                            '<td class="text-center">'+value.season+'</td>' +
                                            '<td class="text-center">'+value.girard+'</td>' +
                                            '<td class="text-center">'+value.color+'</td>' +
                                            '<td class="text-center">'+value.price+'</td>' +
                                            '<td class="text-center">'+that.getMon( value.price , value.discount)+'</td>' +
                                            '<td class="text-center">'+value.discount+'</td>' +
                                            '<td class="text-center">'+value.size_group+'</td>' +
                                            '<td class="text-center">'+sum[0]+'</td>' +
                                            '<td class="text-center">'+sum[1]+'</td>' +
                                            '<td class="text-center">'+sum[2]+'</td>' +
                                            '<td class="text-center">'+sum[3]+'</td>' +
                                            '<td class="text-center">'+sum[4]+'</td>' +
                                            '<td class="text-center">'+sum[5]+'</td>' +
                                            '<td class="text-center">'+sum[6]+'</td>' +
                                            '<td class="text-center">'+sum[7]+'</td>' +
                                            '<td class="text-center">'+sum[8]+'</td>' +
                                            '<td class="text-center">'+sum[9]+'</td>' +
                                            '<td class="text-center">'+sum[10]+'</td>' +
                                            '<td class="text-center">'+sum[11]+'</td>' +
                                            '<td class="text-center jianCount">'+cvs+'</td>' +
                                            '<td class="text-center zheCount">'+that.getDon( value.price , value.discount , oneNum , twoNum , cvs)+'</td>'+
                                            '<td class="text-center diaoCount">'+that.getCou(value.price , oneNum , twoNum , cvs)+'</td>'+
                                            '</tr>';
                                    }
                                    $(".TreeTable tbody").empty();
                                    $(".TreeTable tbody").append(ste);

                                    var er1=0;
                                    var a1=0;
                                    var a3=0;
                                    for(var df=0;df<$(".jianCount").length;df++){
                                        er1=er1+Number($(".jianCount").eq(df).text());
                                        a1=a1+Number($(".zheCount").eq(df).text());
                                        a3=a3+Number($(".diaoCount").eq(df).text());
                                    }
                                    var sf='<tr><td colspan="3">总计</td><td class="text-center"></td><td class="text-center"></td><td class="text-center"></td><td class="text-center"></td><td class="text-center"></td><td class="text-center"></td><td class="text-center"></td><td class="text-center"></td><td class="text-center"></td><td class="text-center"></td><td class="text-center"></td><td class="text-center"></td><td class="text-center"></td><td class="text-center"></td><td class="text-center"></td><td class="text-center"></td><td class="text-center"></td><td class="text-center">'+er1+'</td><td class="text-center">'+a1.toFixed(2)+'</td><td class="text-center">'+a3.toFixed(2)+'</td></tr>'
                                    $(".TreeTable tbody").append(sf);
                                    $(".TreeTable").show();
                                    $(".FourTable").hide();
                                }else {
                                    $(".TreeTable tbody").empty();
                                }
                                if(data.content.data_2.length>0){
                                    var strd='';
                                    for(var value of data.content.data_2){
                                        strd=strd+'<tr>' +
                                            '<td class="text-center">'+value.brand+'</td>' +
                                            '<td class="text-center">'+value.year+'</td>' +
                                            '<td class="text-center">'+value.season+'</td>' +
                                            '<td class="text-center">'+value.cate_3+'</td>' +
                                            '<td class="text-center">'+value.girard+'</td>' +
                                            '<td class="text-center">'+value.color+'</td>' +
                                            '<td class="text-center">'+value.size+'</td>' +
                                            '<td class="text-center">'+value.price+'</td>' +
                                            '<td class="text-center">'+value.code+'</td>' +
                                            '<td class="text-center">'+value.scan_admin+'</td>' +
                                            '<td class="text-center">'+value.created_at+'</td>';
                                    }
                                    $(".FourTable tbody").append(strd);
                                    $(".TreeTable").hide();
                                    $(".FourTable").show();

                                }else{
                                    that.tuiCodes=[];
                                }
                                var bdhtml = window.document.body.innerHTML;//获取当前页的html代码
                                var startStr = "<!--startprint-->";//设置打印开始区域
                                var endStr = "<!--endprint-->";//设置打印结束区域
                                var printHtml = bdhtml.substring(bdhtml.indexOf(startStr) + startStr.length, bdhtml.indexOf(endStr));//从标记里获取需要打印的页面
                                window.document.body.innerHTML = printHtml;//需要打印的页面
                                window.print();
                                window.document.body.innerHTML = bdhtml;//还原界面
                                window.location.reload();


                            }else{

                            }
                        }
                    });
                },
                /*导出*/
                exportBtn(){
                    if(this.ids==''){
                        this.$notify.error({
                            title: '提示',
                            message: "至少选择一个单据导出",
                        });
                        return false;
                    }
                    window.location.href = "/distribution/return-order-export?ids=" + this.ids ;
                },
            }
        });
    </script>
@endsection